/*
Purpose: Clean state-year-level unemployment data from BLS
*/

import delimited "data/raw/la.data.2.AllStatesU.txt", clear

replace series_id = strtrim(series_id)
gen measure = substr(series_id,20,1)
keep if measure=="3" // unemployment rate
ren value unemp_rate 
drop measure

replace unemp_rate = strtrim(unemp_rate)
replace unemp_rate = "" if unemp_rate=="-"
destring unemp_rate, replace

keep if inrange(year,1990,2019)

gen fips = substr(series_id,6,2)
destring fips, replace

gen yob = year - 18 // using unemp rate for 18-year-olds

keep if period=="M13" // these are the annual averages
keep fips yob unemp_rate
ren fips fips_birth
ren unemp_rate unemp_rate_age18
save "data/clean/state_unemployment.dta", replace

